#include "Viewport.h"
#include "Renderable2d.h"
#include "GraphicFactory.h"

namespace Graphics
{
	Renderable2D::Renderable2D(void):m_pViewport(0)
	{

	}

	Renderable2D::~Renderable2D(void)
	{
		if(m_pViewport != 0)
		{
			m_pViewport->Remove(*this);
		}
	}

	void Renderable2D::SetViewport(Viewport* viewport)
	{
		if(viewport == m_pViewport)
		{
			return;
		}
		if(m_pViewport != 0)
		{
			m_pViewport->Remove(*this);
		}
		m_pViewport = viewport;
		if(m_pViewport != 0)
		{
			m_pViewport->Add(*this);
		}
	}

	void Renderable2D::SetSequence(int sequence)
	{
		Renderable::SetSequence(sequence);
		if(m_pViewport != 0)
		{
			m_pViewport->MarkDirty();
		}
	}
}